{include file="../application/admin/view/default/header.html" title="文章管理列表" adminData=$adminData /}

<style>

    .panel-heading a{
        height: 45px;
        width: 140px;
        display: inline-block;
        background: #2ebaae;
        text-align: center;
        line-height: 45px;
        margin-bottom: 20px;
        border-radius: 4px;
        color: #fff;
    }
    .panel-heading a:hover{
        color: #fff !important;
    }

</style>

<div id="main" class=" container  text-slg">
    <div class="panel post ">
        <div class="panel-heading panel_gray">
            <a href="/admin/news/add" class="btn btn-primary btn-lg">添加新闻</a>
        </div>
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th class="text-center">新闻ID</th>
                        <th class="text-center">标题</th>
                        <th class="text-center">编辑人</th>
                        <th class="text-center">发布时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($newsList as $news){ ?>
                    <tr>
                        <td class="text-center">{$news.nid}</td>
                        <td class="text-center">{$news.title}</td>
                        <td class="text-center">{$news.username}</td>
                        <td class="text-center"><?php echo date("y-m-d",strtotime($news['ntime']))?></td>
                        <td class="text-center">
                            <?php if($news['status'] == 1){ ?>
                            <a href="javascript:;" class="downNews" data-id="{$news.nid}">下线</a>
                            <?php }else{ ?>
                            <a href="javascript:;" class="upNews" data-id="{$news.nid}">上线</a>
                            <?php } ?>
                            <a href="/admin/news/edit?nid={$news.nid}" class="editNews" data-id="{$news.nid}">编辑</a>
                            <a href="javascript:;" class="deleteNews" data-id="{$news.nid}">删除</a>
                        </td>
                    </tr>
                    <?php }?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        $('.downNews').on('click',function(){
            $.ajax({
                type:'POST',
                url:'/admin/news/status',
                dataType:'json',
                data:{'nid':$('.downNews').data('id'),'status':0},
                success:function(data){
                    alert(data.msg);
                    if(!data.code){
                        window.location.reload();
                    }
                }
            });
        });
        $('.upNews').on('click',function(){
            $.ajax({
                type:'POST',
                url:'/admin/news/status',
                dataType:'json',
                data:{'nid':$('.upNews').data('id'),'status':1},
                success:function(data){
                    alert(data.msg);
                    if(!data.code){
                        window.location.reload();
                    }
                }
            });
        });
        $('.deleteNews').on('click',function(){
            $.ajax({
                type:'POST',
                url:'/admin/news/delete',
                dataType:'json',
                data:{'nid':$(this).data('id')},
                success:function(data){
                    alert(data.msg);
                    console.log(data);
                    if(!data.code){
                        window.location.reload();
                    }
                }
            });
        });
    })


</script>
</html>